﻿using Microsoft.AspNetCore.Mvc;
using web_api_demo101.Services;

namespace web_api_demo101.Controllers;


[ApiController]
[Route("[controller]")]
public class StudentController : ControllerBase
{
    private readonly IStudentService _studentService;
    public StudentController(IStudentService service)
    {
        _studentService = service;
    }

    [HttpGet("paginationQuery/{page}/{pagesize}")]
    public IActionResult PaginationQuery(int page, int pagesize)
    {
        var res = _studentService.PaginationQuery(page, pagesize);

        return new JsonResult(res);
    }

    [HttpPost("add")]
    public IActionResult Add(Entities.Student stu)
    {
        _studentService.Add(stu);

        return Ok();
    }

    [HttpPost("update/{id}")]
    public IActionResult Update(int id, Entities.Student stu)
    {
        stu.Id = id;
        _studentService.Update(stu);

        return Ok();
    }
}
